package com.gzhu.knowledgeAdmin.service.impl;


import com.gzhu.knowledgeAdmin.common.vo.RecorderVo;
import com.gzhu.knowledgeAdmin.entity.Recorder;
import com.gzhu.knowledgeAdmin.repository.RecorderRepository;
import com.gzhu.knowledgeAdmin.service.RecorderService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class RecorderServiceImpl implements RecorderService {

    @Autowired
    private RecorderRepository recorderRepository;

    @Override
    public List<RecorderVo> getRecorderList() {
        List<Recorder> recorderList = recorderRepository.findAll();

        return recorderList.stream().map(recorder -> {
            RecorderVo recorderVo = new RecorderVo();
            BeanUtils.copyProperties(recorder, recorderVo);
            return recorderVo;
        }).collect(Collectors.toList());
    }

    @Override
    public void updateRecorder(Recorder recorder) {
        recorderRepository.save(recorder);
    }
}
